package com.chia.multienty.core.service.impl;

import com.chia.multienty.core.domain.condition.MasterOrUserCondition;
import com.chia.multienty.core.domain.condition.MasterOrUserOrOAuthCondition;
import com.chia.multienty.core.domain.condition.WechatCondition;
import com.chia.multienty.core.pojo.AppVersion;
import com.chia.multienty.core.mapper.AppVersionMapper;
import com.chia.multienty.core.service.AppVersionService;
import com.chia.multienty.core.mybatis.service.impl.KutaBaseServiceImpl;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chia.multienty.core.domain.dto.AppVersionDTO;
import com.chia.multienty.core.parameter.base.AppVersionDetailGetParameter;
import com.chia.multienty.core.parameter.base.AppVersionPageGetParameter;
import com.chia.multienty.core.parameter.base.AppVersionDeleteParameter;
import com.chia.multienty.core.parameter.base.AppVersionSaveParameter;
import com.chia.multienty.core.parameter.base.AppVersionUpdateParameter;
import com.chia.multienty.core.parameter.base.AppVersionEnableParameter;
import com.chia.multienty.core.parameter.base.AppVersionDisableParameter;
import com.github.yulichang.toolkit.MPJWrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import com.chia.multienty.core.domain.constants.MultientyConstants;
import com.chia.multienty.core.mybatis.MTLambdaWrapper;
import com.chia.multienty.core.util.ListUtil;
import com.chia.multienty.core.domain.enums.StatusEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chia.multienty.core.tools.IdWorkerProvider;
/**
 * <p>
 * 应用版本 服务实现类
 * </p>
 *
 * @author Multi Tenant Auto Generator
 * @since 2024-07-19
 */
@Service
@RequiredArgsConstructor
@Conditional(MasterOrUserOrOAuthCondition.class)
public class AppVersionServiceImpl extends KutaBaseServiceImpl<AppVersionMapper, AppVersion> implements AppVersionService {


    @Override
    public AppVersionDTO getDetail(AppVersionDetailGetParameter parameter) {
        return selectJoinOne(AppVersionDTO.class,
                        MPJWrappers.<AppVersion>lambdaJoin().eq(AppVersion::getVersionId, parameter.getVersionId()));
    }

    @Override
    public void update(AppVersionUpdateParameter parameter) {
        AppVersion appVersion = new AppVersion();
        BeanUtils.copyProperties(parameter, appVersion);
        updateByIdTE(appVersion);
    }

    @Override
    public void delete(AppVersionDeleteParameter parameter) {
        removeByIdTE(parameter.getVersionId());
    }

    @Override
    public IPage<AppVersionDTO> getPage(AppVersionPageGetParameter parameter) {
        return selectJoinListPage(parameter.getPageObj(), AppVersionDTO.class,
                new MTLambdaWrapper<AppVersion>()
                        .solveGenericParameters(parameter)
                        .in(!ListUtil.isEmpty(parameter.getVersionIds()),
                                AppVersion::getVersionId,
                                parameter.getVersionIds())
        );
    }

    @Override
    public void save(AppVersionSaveParameter parameter) {
        AppVersion appVersion = new AppVersion();
        BeanUtils.copyProperties(parameter, appVersion);
        saveTE(appVersion);
        parameter.setVersionId(appVersion.getVersionId());
    }


    @Override
    public void enable(AppVersionEnableParameter parameter) {
        AppVersion appVersion = new AppVersion();
        BeanUtils.copyProperties(parameter, appVersion);
        appVersion.setStatus(StatusEnum.NORMAL.getCode());
        updateByIdTE(appVersion);
    }

    @Override
    public void disable(AppVersionDisableParameter parameter) {
        AppVersion appVersion = new AppVersion();
        BeanUtils.copyProperties(parameter, appVersion);
        appVersion.setStatus(StatusEnum.DISABLED.getCode());
        updateByIdTE(appVersion);
    }
}
